﻿@{
    ViewBag.Title = "登录页面";
    Layout = null;
}

<div id="quan" style="margin: 0 auto;text-align:center;">
    <h1>记住登陆用户信息Demo</h1>
    <div style="margin: 0 auto;text-align:center;border:2px #b6ff00 solid;width:500px;padding:20px;">

        <spqn style="font-weight:bold;">用户名：</spqn>
        <input type="text" id="UserName" name="UserName" value="@ViewBag.UserName" style="border:1px blue solid;height:30px;width:190px;" /><br /><br />

        <spqn style="font-weight:bold;">密&nbsp;&nbsp;&nbsp;码：</spqn>
        <input type="password" id="Pwd" name="Pwd" value="@ViewBag.Pwd" style="border:1px blue solid;height:30px;width:190px;" /><br /><br />

        记住我一周：<input type="checkbox" name="LoginStatus" style="border:1px blue solid;height:20px;width:150px;" /><br /><br />

        <input onclick="logins()" type="button" name="TiJiao" value="登录" style="height:30px;width:150px;background-color:#2ddde2;" />
        <input onclick="Clearlogins()" type="button" name="Clears" value="清空登录信息" style="height:30px;width:150px;background-color:#2ddde2;" />
    </div>
</div>
<script src="~/Scripts/jquery-3.3.1.min.js"></script>
<script>
    //提交登录按钮事件
    function logins() {
        var ids = document.getElementsByName("LoginStatus");
        var flag = false;
        var Status = 0;
        for (var i = 0; i < ids.length; i++) {
            if (ids[i].checked) {
                flag = true;
                break;
            }
        }
        //Status:1 表示勾选了记住复选框，Status:2 表示没有勾选记住复选框
        if (!flag) {
            Status = 2;
        } else {
            Status = 1;
        }
        
        //请求路径【传值测试】
        var uri = '/Home/ToLogin';

        //传递参数
        var hbre = {
            UserName: $("#UserName").val(),
            Pwd: $("#Pwd").val(),
            Status: Status
        };
        //alert(JSON.stringify(hbre));
        //请求实体
        $.ajax({
            url: uri,
            type: "post",
            data: JSON.stringify(hbre),
            contentType: "application/json",
            dataType: "json",
            success: function (data) {
                //alert(JSON.stringify(data));
                if (data.UserName != "") {
                    location.href = "/Home/IndexAdmin";
                }
            }
        });
    }

    //清空登录信息
    function Clearlogins() {
        //传递参数
        var hbre = {};

        //请求实体
        $.ajax({
            url: '/Home/ClearLogin',
            type: "post",
            data: JSON.stringify(hbre),
            contentType: "application/json",
            dataType: "json",
            success: function (data) {
                //alert(JSON.stringify(data));
                if (data.result == true) {
                    location.href = "/Home/Login";
                }
            }
        });
    }
</script>
